import { AccountApiResponse } from '@/types/account';

const API_BASE_URL = 'http://47.100.39.125:1000/api/ucenter';

/**
 * 获取账户信息
 * @param uniqueStr 用户唯一标识
 * @returns Promise<AccountApiResponse>
 */
export async function fetchAccountInfo(uniqueStr: string): Promise<AccountApiResponse> {
  try {
    const response = await fetch(`${API_BASE_URL}/account/info`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Accept': '*/*',
        'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
      },
      body: JSON.stringify({
        unique_str: uniqueStr
      })
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const data: AccountApiResponse = await response.json();
    
    if (data.code !== 200) {
      throw new Error(data.message || '获取账户信息失败');
    }

    return data;
  } catch (error) {
    console.error('获取账户信息失败:', error);
    throw error;
  }
}